<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ChangeTch</title>
<script src="../jquery-3.5.1.js"></script>
<script src="../jquery.cookie.js"></script>

<style>
body
{
font-size:75%;
font-family:verdana,arial,'sans serif';

background-repeat:repeat-x;
background-color:#FFFFF0;
color:#000080;

}

h1 {font-size:200%;}
h2 {font-size:140%;}
h3 {font-size:110%;}

th {background-color:#ADD8E6;}

ul {list-style:circle;}
ol {list-style:upper-roman;}

a:link {color:#000080;}
a:hover {color:red;}

</style>
<script>var userid = sessionStorage.getItem('testKey');
if(userid == null || userid == "")
	{
	window.location = "/login.html";
	}
</script>
<script type="text/javascript">
var url = decodeURI(window.location.href);

var argsIndex = url .split("?tid=");
var tid = argsIndex[1];
window.onload =function(){
	 $.ajax({
		 
	        type: 'GET',
	        url: "/teachers/"+tid,
	        contentType: "application/json;cherset=utf-8",
	        dataType: "json",
	        success: function (data){
	               $("#tid").val(data.tid);
	               $("#name").val(data.name);
	               $("#password").val(data.password);
	              } ,
	        error: function (data) {
	            alert("error:" + JSON.stringify(data));}
	    });
	
}

function editTch(){
	var tid= $("#tid").val();
	 $.ajax({
	        url:'/teachers/' + tid ,
	        data:$('#edit').serialize(),
	        type:'PUT',
	        dataType:'json',
	        
	        success:function(data){
	        
	        if(data == "success")
	        history.back(-1);
	        },
	        error:function(){
	        	
		        history.back(-1);
	        },
})
}
</script>
</head>
<body>
	<em>Rewrite information down here</em>
	
	<form method="post" action="/teachers" id="edit">
		<table>
			<tr>
				<td>学号</td>
				<td><input type="text" name="tid" id="tid" readonly/></td>
			</tr>
			<tr>
				<td>姓名</td>
				<td><input type="text" name="name" id="name" /></td>
			</tr>
			<tr>
				<td>密码</td>
				<td><input type="text" name="password" id="password" /></td>
			</tr>
			<tr>
				<td><button type="button" onclick="editTch()">修改</button></td>
			</tr>
		</table>
	</form>
</body>
</html>